﻿// ReSharper disable InconsistentNaming

using System.Collections.Generic;
using Common;
using ImageProcessing.Common;
using ImageProcessing.Tests.Engine;
using NUnit.Framework;

namespace ImageProcessing.Tests.Common
{
    [TestFixture]
    public class ConvexHullTests
    {
        private ConvexHull _convexHull;

        private readonly List<InterestPoint> sqaureBox = new List<InterestPoint>
                               {
                                   new InterestPoint(new PointInfo()){x=1,y=1},
                                   new InterestPoint(new PointInfo()){x=5,y=1},
                                   new InterestPoint(new PointInfo()){x=5,y=5},
                                   new InterestPoint(new PointInfo()){x=1,y=5}
                               };

        private readonly List<InterestPoint> skewedBox = new List<InterestPoint>
                               {
                                   new InterestPoint(new PointInfo()){x=1,y=1},
                                   new InterestPoint(new PointInfo()){x=5,y=1},
                                   new InterestPoint(new PointInfo()){x=9,y=5},
                                   new InterestPoint(new PointInfo()){x=4,y=5}
                               };

        private readonly List<InterestPoint> triangle = new List<InterestPoint>
                                                        {
                                                            new InterestPoint(new PointInfo()){x = 1,y = 1},
                                                            new InterestPoint(new PointInfo()){x = 10,y = 1},
                                                            new InterestPoint(new PointInfo()){x = 5,y = 5},
                                                        };

        [Test]
        public void GetBoundedPoints_AllPointsBoundryPoints_True()
        {
            Assert.IsTrue(ListComparerHelper.EqualListValues(sqaureBox, ConvexHull.GetBoundedPoints(sqaureBox)));

            Assert.IsTrue(ListComparerHelper.EqualListValues(skewedBox, ConvexHull.GetBoundedPoints(skewedBox)));

            Assert.IsTrue(ListComparerHelper.EqualListValues(triangle, ConvexHull.GetBoundedPoints(triangle)));
        }

        [Test]
        public void GetBoundedPoints_AllPointsWithin_True()
        {
            var extraPoints = new List<InterestPoint> { new InterestPoint(new PointInfo()) { x = 2, y = 2 }, new InterestPoint(new PointInfo()) { x = 4, y = 4 } };

            var extraSquarePoints = new List<InterestPoint>(sqaureBox);
            extraSquarePoints.AddRange(extraPoints);

            var extraSkewedPoints = new List<InterestPoint>(skewedBox);
            extraSkewedPoints.AddRange(extraPoints);

            var extraTrianglePoints = new List<InterestPoint>(triangle) { new InterestPoint(new PointInfo()) { x = 5, y = 3 } };

            Assert.IsTrue(ListComparerHelper.EqualListValues(sqaureBox, ConvexHull.GetBoundedPoints(extraSquarePoints)));

            Assert.IsTrue(ListComparerHelper.EqualListValues(skewedBox, ConvexHull.GetBoundedPoints(extraSkewedPoints)));

            Assert.IsTrue(ListComparerHelper.EqualListValues(triangle, ConvexHull.GetBoundedPoints(extraTrianglePoints)));
        }
    }
}
